#include<iostream>
#include <sys/socket.h>
#include "../source/public.h"

void test_Lookup()
{
    using namespace std;

    std::vector<framework::Address::ptr> addrs;

    std::string host = "www.baidu.com:ftp";
    bool b = framework::Address::Lookup(addrs, host, AF_INET);
    if(!b)
    {
        cout << "Lookup error" << endl;
    }
    for(const auto& t : addrs)
    {
        cout << t->toString() << endl;        
    }

}

void testGetInterfaceAddresses()
{
    using namespace std;

    std::multimap<std::string, std::pair<framework::Address::ptr, uint32_t>> result;
    bool b = framework::Address::GetInterfaceAddresses(result, AF_INET6);

    if(!b)
    {
        cout << "GetInterfaceAddresses error" << endl;
        return;
    }

    for(const auto& t: result)
    {
        cout << t.first << "\t" << t.second.first->toString() << "\t" << t.second.second << endl;
    }
}

void testIpv4()
{
    using namespace std;
    auto addr = framework::IPAddress::Create("192.168.1.42", 20);
    //auto addr = framework::IPAddress::Create("www.baidu.com", 20);
    if(addr)
    {
        cout << addr->toString() << std::endl;
    }
}

int main(void)
{
    test_Lookup();
    testGetInterfaceAddresses();
    testIpv4();

    return 0;
}